<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>
<body>


<script>
    //获取code参数
    function getUrlParam(name){
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
    var appId = 'wx90d3ae983a46ac18';
    var myUrl = getUrlParam("myUrl");
    function wxLogin(appId){
        var access_code = getUrlParam("code");
        if(access_code){
            var urlArr = myUrl.split("?");
            if(urlArr.length > 1){
                window.location.replace(urlArr[0]+"?code="+access_code+"&"+urlArr[1]);
            }else{
                window.location.replace(urlArr[0]+"?code="+access_code);
            }

        }else{
            var url=encodeURIComponent(window.location.href);
            window.location.replace("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+url+"&response_type=code&scope=snsapi_userinfo&state=STATE&component_appid=wx20d497ea5cee51ba#wechat_redirect");
        }
    }
    wxLogin(appId);
</script>
</body>
</html>